package ui.comp;

import java.util.List;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;

import type.Proxy;
import ui.custom.ProxyTable;
import util.H2DB;

public class ProxyComposite extends Composite {
	private ProxyTable table;
	public ProxyComposite(Composite parent, int style) {
		super(parent, style);
		List<Proxy> accts = initData();
		this.setLayout(new FillLayout());
		Composite top = new Composite(this, SWT.NONE);
		top.setLayout(new GridLayout(1, true));
		table = new ProxyTable(top, accts);
		if(accts.size()==1){
			Proxy testData = (Proxy) accts.get(0);
			if(testData.getId().equals("test")){
				table.clear();
			}
		}
	}

	private List<Proxy> initData() {
		List<Proxy> tmp = null;
		try {
			tmp = H2DB.getData(Proxy.class);
			if(tmp.size()==0){
				tmp.add(new Proxy("test","",""));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return tmp;
	}

	public ProxyTable getTable() {
		return table;
	}

}
